package com.ruoyi.collect.controller;

import com.ruoyi.collect.domain.TbCollect;
import com.ruoyi.collect.service.ITbCollectService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收藏Controller
 * 
 * @author 劳雅玲
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/collect/collect")
public class TbCollectController extends BaseController
{
    @Autowired
    private ITbCollectService tbCollectService;

    /**
     * 查询收藏列表
     */
    @PreAuthorize("@ss.hasPermi('collect:collect:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCollect tbCollect)
    {
        startPage();
        List<TbCollect> list = tbCollectService.selectTbCollectList(tbCollect);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @PreAuthorize("@ss.hasPermi('collect:collect:export')")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCollect tbCollect)
    {
        List<TbCollect> list = tbCollectService.selectTbCollectList(tbCollect);
        ExcelUtil<TbCollect> util = new ExcelUtil<TbCollect>(TbCollect.class);
        util.exportExcel(response, list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('collect:collect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCollectService.selectTbCollectById(id));
    }

    /**
     * 新增收藏
     */
    @PreAuthorize("@ss.hasPermi('collect:collect:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCollect tbCollect)
    {
        return toAjax(tbCollectService.insertTbCollect(tbCollect));
    }

    /**
     * 修改收藏
     */
    @PreAuthorize("@ss.hasPermi('collect:collect:edit')")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCollect tbCollect)
    {
        return toAjax(tbCollectService.updateTbCollect(tbCollect));
    }

    /**
     * 删除收藏
     */
    @PreAuthorize("@ss.hasPermi('collect:collect:remove')")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCollectService.deleteTbCollectByIds(ids));
    }


    /**
     * 删除收藏
     */
    @PreAuthorize("@ss.hasPermi('collect:collect:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @DeleteMapping("del")
    public AjaxResult del(@RequestBody TbCollect tbCollect)
    {
        return toAjax(tbCollectService.del(tbCollect));
    }
}
